package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsBiddingMapper;
import net.anzhuo.entity.GsBidding;
import net.anzhuo.service.GsBiddingService;
@Service
public class GsBiddingServiceImpl implements GsBiddingService {

	@Autowired
	private GsBiddingMapper gsBiddingMapper;
	
	@Override
	public GsBidding getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsBiddingMapper.getById(id);
	}

	@Override
	public List<GsBidding> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsBiddingMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsBidding> getListWithPage(GsBidding gsBidding) {
		PaginationVO<GsBidding> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsBiddingMapper.getListWithPage(gsBidding));
		paginationVO.setTotalCount(gsBiddingMapper.getCount(gsBidding.getCoMd5()));
		paginationVO.setTotalPage((gsBiddingMapper.getCount(gsBidding.getCoMd5()) + gsBidding.getPageSize() -1)  / gsBidding.getPageSize()+1);
		paginationVO.setPageNo(gsBidding.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsBidding> getList() {
		// TODO Auto-generated method stub
		return  gsBiddingMapper.getList();
	}

	@Override
	public List<GsBidding> getList(GsBidding gsBidding) {
		// TODO Auto-generated method stub
		return gsBiddingMapper.getListByQuery(gsBidding);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsBidding gsBidding) {
		// TODO Auto-generated method stub
		gsBiddingMapper.update(gsBidding);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsBidding gsCheck) {
		// TODO Auto-generated method stub
		gsBiddingMapper.save(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsBidding gsCheck = gsBiddingMapper.getById(id);
		if (gsCheck == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsBiddingMapper.update(gsCheck);

	}

}
